from django.db import models
from common.models import ObjectModel


class Order(ObjectModel):
    state = models.CharField(max_length=16)
    buyer = models.ForeignKey('user.User', on_delete=models.CASCADE)
    sum_money = models.DecimalField(max_digits=10, decimal_places=2)

    class Meta:
        db_table = 'order'
        ordering = ('-created_at',)


class OrderItem(ObjectModel):
    buy_num = models.IntegerField()
    sum_money = models.DecimalField(max_digits=10, decimal_places=2)
    product = models.ForeignKey('product.Product', on_delete=models.CASCADE)
    order = models.ForeignKey('order.Order', on_delete=models.CASCADE)
    origin_price = models.DecimalField(max_digits=10, decimal_places=2)
    price = models.DecimalField(max_digits=10, decimal_places=2)

    class Meta:
        db_table = 'orderitem'
        ordering = ('-created_at',)
